﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApp.Models;
using WpfApp.Services;

namespace WpfApp.Views
{
    /// <summary>
    /// Register.xaml 的交互逻辑
    /// </summary>
    public partial class Register : Window
    {
        public Register()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string userName = userNameBox.Text;
            string password = passwordBox.Password;
            string confirm = passwordBox2.Password;
            DataService ds=new DataService();
            if (userName == "" || password == "") MessageBox.Show("账号或密码不能为空！");
            else if (password != confirm) MessageBox.Show("密码不一致");
            else if(MainWindow.data.Register(userName,password))
            {
                MessageBox.Show("注册成功");
                Application.Current.MainWindow.IsEnabled = true;
                Application.Current.MainWindow.Activate();
                this.Close();
            } else
            {
                MessageBox.Show("用户名已存在");
            }
            
        }
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            Application.Current.MainWindow.IsEnabled = true;
            Application.Current.MainWindow.Activate();
        }
    }
}
